describe('See product list controller', function(){
	
	var controller;
	
	beforeEach(function(){
		var t_appCtrl = App.ApplicationController.create();
		var t_alertCtrl = App.AlertController.create();
		var t_loadingCtrl = App.LoadingController.create();
		
		App.SeeProductListController.reopen({
			
			init:function(){
				this.set('controllers.application', t_appCtrl);
				this.set('controllers.alert', t_alertCtrl);
				this.set('controllers.loading', t_loadingCtrl);
			}
			
		});

		controller = App.SeeProductListController.create();

	});
	
	it('should invoke api_accounts productList in prepareController', function(){
		spyOn(App.api_accounts, 'productList');
		
		expect(controller.get('productTypes').length).toEqual(0);
		controller.prepareController();
		expect(controller.get('productTypes').length).toEqual(2);
		
		expect(App.api_accounts.productList).toHaveBeenCalled();
	});

    it('should not refresh the page if user click back button', function(){
        spyOn(App.RouteHistory, "previousRoute").andReturn("see.transactionHistory");
        spyOn(App.api_accounts, 'productList');
        spyOn(controller,"set");
        controller.prepareController();
        expect(controller.set).toHaveBeenCalledWith('refreshList', false);
    });

    it('should return  not refresh the page if user click back button', function(){
        var t_exp = new BreezeException({
        	errorCode: 123,
        	errorMessage: 'error'
        });
        spyOn(App.api_accounts, 'productList').andCallFake(function(callback) {
            callback(t_exp);
        })
        controller.prepareController();
    });

	it("should invoke seesion' s getProductList function to populate productList", function(){
		var t_session = App.getSession();
		spyOn(t_session, 'getProductList').andReturn({iHave:{totalBalance:0, list:[]}, iOwe:{totalBalance:0, list:[]}});
		
		controller.populateProducts();
		expect(t_session.getProductList).toHaveBeenCalled();
	});
	
	it("account should show transaction history", function() {
		var account = App.BaseAccount.create();
        account.requiresTransactionHistory = true;

        spyOn(controller, 'transitionTo');

        controller.selectListItem(account);

        expect(controller.transitionTo).toHaveBeenCalledWith('see.transactionHistory', account);
    });

    it("account should not show transaction history", function() {
    	var account = App.BaseAccount.create();
        account.requiresTransactionHistory = false;

        spyOn(controller, 'transitionTo');

        controller.selectListItem(account);

        expect(controller.transitionTo).toHaveBeenCalledWith('see.accountDetail', account);
    });
    
});